package com.me.jingdongshop.model.protocol;


import com.me.jingdongshop.model.bean.Address;
import com.me.jingdongshop.model.bean.AddressDefault;
import com.me.jingdongshop.model.bean.Cart;
import com.me.jingdongshop.model.bean.Category;
import com.me.jingdongshop.model.bean.Help;
import com.me.jingdongshop.model.bean.HelpDetail;
import com.me.jingdongshop.model.bean.Home;
import com.me.jingdongshop.model.bean.HomeQuick;
import com.me.jingdongshop.model.bean.HomeRecommendedBrand;
import com.me.jingdongshop.model.bean.HotproductBean;
import com.me.jingdongshop.model.bean.LimitbuyBean;
import com.me.jingdongshop.model.bean.LocationList;
import com.me.jingdongshop.model.bean.LoginBean;
import com.me.jingdongshop.model.bean.NewproductBean;
import com.me.jingdongshop.model.bean.ProComment;
import com.me.jingdongshop.model.bean.ProFavo;
import com.me.jingdongshop.model.bean.Product;
import com.me.jingdongshop.model.bean.ProductDes;
import com.me.jingdongshop.model.bean.ProductList;
import com.me.jingdongshop.model.bean.SearchProduct;
import com.me.jingdongshop.model.bean.SearchRecommend;
import com.me.jingdongshop.model.bean.UserInfo;

import java.util.Map;

import retrofit2.http.Query;

/**
 * Created on 2017/5/4.
 * 各模块请求方法
 * @author Chilam
 */

public class CommonProtocol extends BaseProtocol {

    /** 请求首页数据 */
    public void getHomeData(HttpCallback callback){
        super.execute(super.getService().getHome(),
                callback,IHttpService.HTTP_HOME,Home.class);
    }
    /** 请求首页数据 */
    public void getSearchRec(HttpCallback callback){
        super.execute(super.getService().getSearchRec(),
                callback,IHttpService.HTTP_SEARCH_REC,SearchRecommend.class);
    }
    /** 请求搜索数据 */
    public void getSearchData(HttpCallback callback,int page, int pageNum, String orderBy, String keyword){
        super.execute(super.getService().getSearch(page,pageNum,orderBy,keyword),
                callback,IHttpService.HTTP_SEARCH, ProductList.class);
    }

    /** 请求首页shop数据 */
    public void getShopData(HttpCallback callback){
        super.execute(super.getService().getHome(),
                callback,IHttpService.HTTP_HOME_SHOP,Home.class);
    }

    //专题及品牌
    /** 促销快报（可能是发现页面顶部轮播图） */
    public void getTopic(HttpCallback callback){
        super.execute(super.getService().getTopic(1,8),
                callback,IHttpService.HTTP_TOPIC, HomeQuick.class);
    }
    /** 推荐品牌（发现） */
    public void getBrandData(HttpCallback callback){
        super.execute(super.getService().getBrand(),
                callback,IHttpService.HTTP_BRAND, HomeRecommendedBrand.class);
    }
    /** 限时抢购 */
    public void getLimitbuy(HttpCallback callback){
        super.execute(super.getService().getLimitbuy(1,10),
                callback, IHttpService.HTTP_LIMITBUY, LimitbuyBean.class);
    }

    /** 促销快报 */
    public void getHomeQuick(HttpCallback callback){
        super.execute(super.getService().getTopic(1,10),
                callback, IHttpService.HTTP_TOPIC, HomeQuick.class);
    }

    /** 新品上架
     * 第三个参数为排序类型：默认为销量降序
     */
    public void getNewproduct(HttpCallback callback){
        super.execute(super.getService().getNewproduct(1,10,"saleDown"),
               callback, IHttpService.HTTP_NEWPRODUCT, NewproductBean.class);
    }
    /** 热门单品
     * 第三个参数为排序类型：默认为销量降序
     */
    public void getHotproduct(HttpCallback callback){
        super.execute(super.getService().getHotproduct(1,10,"saleDown"),
                callback, IHttpService.HTTP_HOTPRODUCT, HotproductBean.class);
    }

    //分类及详情
    /** 分类请求 */
    public void getCategory(HttpCallback callback, int page, int pageNum) {
        super.execute(super.getService().getCategory(page, pageNum),
                callback, IHttpService.HTTP_CATEGORY, Category.class);
    }
    /** 商品列表 */
    //默认排序 销量降序
    public void getProductList(HttpCallback callback, int page, int pageNum,int cId,String orderby) {
        super.execute(super.getService().getProductList(page, pageNum,cId,orderby),
                callback, IHttpService.HTTP_PRODUCTLIST, ProductList.class);
    }

    //价格升序
    public void getPropriceUp(HttpCallback callback, int page, int pageNum,int cId,String orderby) {
        super.execute(super.getService().getProductList(page, pageNum,cId,orderby),
                callback, IHttpService.HTTP_PRODUCTLIST_priceUp, ProductList.class);
    }
    //价格降序
    public void getPropriceDowm(HttpCallback callback, int page, int pageNum,int cId,String orderby) {
        super.execute(super.getService().getProductList(page, pageNum,cId,orderby),
                callback, IHttpService.HTTP_PRODUCTLIST_priceDown, ProductList.class);
    }
    //评论降序
    public void getProcommentDown(HttpCallback callback, int page, int pageNum,int cId,String orderby) {
        super.execute(super.getService().getProductList(page, pageNum,cId,orderby),
                callback, IHttpService.HTTP_PRODUCTLIST_commentDown, ProductList.class);
    }
    //上架降序
    public void getProshelvesDown(HttpCallback callback, int page, int pageNum,int cId,String orderby) {
        super.execute(super.getService().getProductList(page, pageNum,cId,orderby),
                callback, IHttpService.HTTP_PRODUCTLIST_shelvesDown, ProductList.class);
    }


    /** 商品详情 */
    public void getProduct(HttpCallback callback, int pid){
        super.execute(super.getService().getProduct(pid),
                    callback,IHttpService.HTTP_PRODUCT, Product.class);
    }
    /** 商品描述 */
    public void getProductDes(HttpCallback callback, int pId){
        super.execute(super.getService().getProductDes(pId),
                    callback,IHttpService.HTTP_PRODUCT_DES, ProductDes.class);
    }
    /** 商品评论 */
    public void getProComment(HttpCallback callback, int page, int pageNum){
        super.execute(super.getService().getProComment(page,pageNum),
                    callback,IHttpService.HTTP_PRODUCT_COMMENT, ProComment.class);
    }
    /** 商品收藏 */
    public void getProFavo(HttpCallback callback,int pId){
        super.execute(super.getService().getProFavo(pId),
                    callback,IHttpService.HTTP_PRODUCT_FAVO, String.class);
    }
    /** 收藏夹 */
    public void getFavo(HttpCallback callback,int userId,int page, int pageNum){
        super.execute(super.getService().getFavo(userId, page,pageNum),
                callback,IHttpService.HTTP_FAVO, ProFavo.class);
    }

    //购物车
    /** 进入购物车 */
    public void postCart(HttpCallback callback, String sku){
        super.execute(super.getService().getCart(sku),
                callback,IHttpService.HTTP_CART, Cart.class);
    }
    /** 修改数量 */
    //同上
    /** 删除商品 */
    //同上
    //我的账户
    /** 登录 */
    public void postLogin(HttpCallback callback, String username,String password){
        super.execute(super.getService().login(username,password),
                callback,IHttpService.HTTP_LOGIN, LoginBean.class);
    }
    /** 注册 */
    public void postRegister(HttpCallback callback,String username, String password){
        super.execute(super.getService().register(username,password),
                callback, IHttpService.HTTP_REGISTER, LoginBean.class);
    }
    /** 账户中心
//     * @param uid 账户id
     */
    public void getUserInfo(HttpCallback callback, String uid){
        super.execute(super.getService().getUserInfo(uid),
                callback, IHttpService.HTTP_USERINFO, UserInfo.class);
    }
    /** 注销 */
    public void getLogout(HttpCallback callback){
        super.execute(super.getService().logout(),
                callback, IHttpService.HTTP_LOGOUT, String.class);
    }


    /** 帮助中心*/
//    IHttpService.HTTP_HELP:标识，用于区分到时拿的数据哪个是哪个
    public void getHelpCenter(HttpCallback callback){
        super.execute(super.getService().getHelpCenter(),
                callback, IHttpService.HTTP_HELP, Help.class);
    }

    /** 帮助中心:内容  */
//    IHttpService.HTTP_HELP:标识
    public void getHelpDetail(HttpCallback callback,int id){
        super.execute(super.getService().getHelpDetail(id),
                callback, IHttpService.HTTP_HELP_DETAIL, HelpDetail.class);

    }
    /** 请求地址列表—省*/
    public void getLocation(HttpCallback callback,int id) {
        super.execute(super.getService().getlocation(id),
                callback, IHttpService.HTTP_LOCATION, Address.class);
    }
    /** 请求地址列表—市*/
    public void getCity(HttpCallback callback,int id) {
        super.execute(super.getService().getlocation(id),
                callback, IHttpService.HTTP_CITY, Address.class);
    }
    /** 请求地址列表—县*/
    public void getCounty(HttpCallback callback,int id) {
        super.execute(super.getService().getlocation(id),
                callback, IHttpService.HTTP_COUNTY, Address.class);
    }
    /**
     * 保存地址
     *
     * @param uid
     * @param map
     */
    public void saveAddAddress(HttpCallback callback, String uid, Map<String, String> map) {
        super.execute(super.getService().saveAddress(uid,map),
                callback, IHttpService.HTTP_SAVE_ADDRESS, LocationList.class);
    }
    /** 请求地址列表*/
    public void getAddressList(HttpCallback callback, String uid) {
        super.execute(super.getService().getAddressList(uid),
                callback, IHttpService.HTTP_ADDRESS_LIST, LocationList.class);
    }
    /** 设置默认地址 */
    public void getAddressDefault(HttpCallback callback, String uid, int id) {
        super.execute(super.getService().getAddressDefault(uid,id),
                callback, IHttpService.HTTP_ADDRESS_DEF, AddressDefault.class);
    }
}
